﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using OA.DBUtility;

namespace OA
{
    public static class ConvertHelper
    {
        public static int ToInt32(this string str)
        {
            int result;
            if (int.TryParse(str, out result))
            {
                return result;
            }
            return int.MinValue;
        }
     

        public static List<string> ToAttributeList<T>(this T t1)
        {
            Type t = typeof(T);
            List<string> list = new List<string>();
            foreach (PropertyInfo info in t.GetProperties(BindingFlags.Public | BindingFlags.Instance))
            {
                object[] objs = info.GetCustomAttributes(typeof(DataField), true);
                if (objs.Length <= 0) continue;
                DataField obj = objs[0] as DataField;
                if (obj.Name.ToLower() == "id" || obj.Name.ToLower() == "createtime") continue;
                list.Add(obj.Name);
            }
            return list;
        }
    }
}
